as Borisy did I managed to have it working with by getting the undo manager from the environment on the ContentView
@Environment(\.modelContext) private var modelContext
@Environment(\.undoManager) private var undoManager
Then I use the onAppear modifier
.onAppear() {
modelContext.undoManager = undoManager
}
Then it works as expected.